'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ManageChooseperformanceCtrl
 * @description
 * # ManageChooseperformanceCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ManageChooseperformanceCtrl', function ($scope, $window, $rootScope, Util, openApi, PagingService) {
        var relModuleObj;
        var param = {};
        // 获取搜索所需参数以及标题信息
        relModuleObj = Util.getDataforsearch();
        $scope.title = relModuleObj.selectTabContent;
        param.relatedModule = relModuleObj.selectTab;
        param = angular.extend(param, relModuleObj.param || {});
        $scope.isSelectindex = -1;
        // 选择后回传的数据
        var returnData;
        $scope.isSelect = function (index) {
            return $scope.isSelectindex == index
        }
        $scope.choosePeople = function (index) {
            $scope.isSelectindex = index;
            $scope.submit()
        }
        // 过滤逻辑
        $scope.picker = {};
        var hideDialog = function () {
            $scope.picker = {};
            $rootScope.showMasker = false;
            $scope.showCerPicker = false;
        };
        $scope.cacelDialog = function () {
            hideDialog();
        };
        // 验证是否输入完整
        var showDialog = function () {
            var param = {};
            param.type = "工程类型";
            Util.getKeyValue(param, function (data) {
                $scope.resiTypeList = data.data
                $rootScope.showMasker = true;
                $scope.showCerPicker = true;
            })
        };
        // 类型变后都清空
        $scope.projectTypechange = function (data) {
            $scope.picker.operation1 = "";
            $scope.picker.kpiValue1 = "";
            var param = {};
            param.type = "工程类型";
            param.parent = data;
            Util.getKeyValue(param, function (data) {
                $scope.kpiList = data.data
            })
        };
        $scope.searchID = function () {
            showDialog()
        };
        $scope.submit = function () {
            var filterData;
            if ($scope.isSelectindex == -1) {
                Util.Toast("请选择");
                return;
            }
            if ($scope.taskList.items) {
                // 返回的字段value
                var valuePropertys = { "pkId": "performanceId", "projectName": "projectName" }
                filterData = Util.filterSelectData($scope.taskList.items[$scope.isSelectindex], valuePropertys)
                // relModuleObj包含用来回显的值以及返回的内容
                relModuleObj.filterData = filterData;
                Util.savaDataforsearch(relModuleObj)
                $window.history.back();
            }
        }
        $scope.search = function () {
            if ($scope.picker.kpiName1) {
                if (!$scope.picker.operation1 || !$scope.picker.kpiValue1) {
                    Util.Toast("请选择业绩指标范围和值");
                    return;
                }
            }
            $scope.picker.getCanBorrow = 1;
            $scope.taskList = new PagingService(openApi.borPerformance, $scope.picker);
            hideDialog();
        }
        $scope.search();
        $scope.rangelist = [['等于', 1], ['大于或等于', 2], ['小于或等于', 3], ['大于', 4], ['小于', 5], ['不等于', 6], ['包含(文字)', 7]]
    });
